<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      <a-row>

	<a-col :span="12">
        <a-form-item label="花名册的ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['wxUserId', validatorRules.wxUserId]" placeholder="请输入花名册的ID"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['typeId', validatorRules.typeId]" placeholder="请输入类型"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="员工姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['name', validatorRules.name]" placeholder="请输入员工姓名"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="英文名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['nameEn', validatorRules.nameEn]" placeholder="请输入英文名"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['gender', validatorRules.gender]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =USER_SEX" placeholder="请选择性别"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择出生日期" v-decorator="['birthday', validatorRules.birthday]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="身份证" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['idCard', validatorRules.idCard]" placeholder="请输入身份证"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="婚姻状况" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['wedlock', validatorRules.wedlock]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =EMP_MARITAL_STATUS" placeholder="请选择婚姻状况"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['nationId', validatorRules.nationId]" placeholder="请输入民族"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="籍贯" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['nativePlace', validatorRules.nativePlace]" placeholder="请输入籍贯"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="政治面貌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['politicId']" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =EMP_PARTY" placeholder="请选择政治面貌"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['email', validatorRules.email]" placeholder="请输入邮箱"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="电话号码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['phone', validatorRules.phone]" placeholder="请输入电话号码"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="联系地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['address']" placeholder="请输入联系地址"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="所属部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['departmentId', validatorRules.departmentId]" placeholder="请输入所属部门"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['jobLevelId', validatorRules.jobLevelId]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =JOB_LEVEL" placeholder="请选择职称ID"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="聘用形式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['engageForm']" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =WORK_TYPE" placeholder="请选择聘用形式"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="最高学历" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['tiptopDegree', validatorRules.tiptopDegree]" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId = EMP_EDUCATION" placeholder="请选择最高学历"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="所属专业" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['specialty', validatorRules.specialty]" placeholder="请输入所属专业"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="毕业院校" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['school', validatorRules.school]" placeholder="请输入毕业院校"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="个人材料（学历证书）" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-image-upload isMultiple v-decorator="['eduPath']"></j-image-upload>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="工龄" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['workAge', validatorRules.workAge]" placeholder="请输入工龄"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="入职日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择入职日期" v-decorator="['beginDate', validatorRules.beginDate]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="在职状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['workState']" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =EMP_WORK_STATE" placeholder="请选择在职状态"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="工号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['workId']" placeholder="请输入工号"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="合同关系公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['companyName']" placeholder="请输入合同关系公司"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="合同期限" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['contTerm', validatorRules.contTerm]" placeholder="请输入合同期限"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="转正日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择转正日期" v-decorator="['conversionTime', validatorRules.conversionTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="离职日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择离职日期" v-decorator="['notWorkDate']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="合同起始日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择合同起始日期" v-decorator="['beginContract', validatorRules.beginContract]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="合同终止日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择合同终止日期" v-decorator="['endContract', validatorRules.endContract]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['uploadPath']" :isMultiple="false" :trigger-change="true"></j-upload>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="户籍类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['household']" :trigger-change="true" dictCode="DataDictionary,description,dictionaryCode, dictionaryTypeId =HOUSEHOLD" placeholder="请选择户籍类型"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="户籍所在地" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['householdLocation', validatorRules.householdLocation]" placeholder="请输入户籍所在地"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="工作地点" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['workAddress']" placeholder="请输入工作地点"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="直属上级" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['reportTo']" placeholder="请输入直属上级"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="预计入职日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择预计入职日期" v-decorator="['estimateBeginDate', validatorRules.estimateBeginDate]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="银行卡号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bankCard', validatorRules.bankCard]" placeholder="请输入银行卡号"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="开户行" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bankOfDeposit', validatorRules.bankOfDeposit]" placeholder="请输入开户行"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="紧急联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['emergencyContact']" placeholder="请输入紧急联系人"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="联系人关系" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['contactRelationship']" placeholder="请输入联系人关系"></a-input>
        </a-form-item>
        </a-col>
	<a-col :span="12">
        <a-form-item label="联系人电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['contactNumber', validatorRules.contactNumber]" placeholder="请输入联系人电话"></a-input>
        </a-form-item>
        </a-col>
        </a-row>
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JUpload from '@/components/jeecg/JUpload'
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  export default {
    name: "HrEmployeeModal",
    components: { 
      JDate,
      JUpload,
      JImageUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          wxUserId: {
            rules: [
              { required: true, message: '请输入花名册的ID!'},
            ]
          },
          typeId: {
            rules: [
              { required: true, message: '请输入类型!'},
            ]
          },
          name: {
            rules: [
              { required: true, message: '请输入员工姓名!'},
            ]
          },
          nameEn: {
            rules: [
              { required: true, message: '请输入英文名!'},
            ]
          },
          gender: {
            rules: [
              { required: true, message: '请输入性别!'},
            ]
          },
          birthday: {
            rules: [
              { required: true, message: '请输入出生日期!'},
            ]
          },
          idCard: {
            rules: [
              { required: true, message: '请输入身份证!'},
            ]
          },
          wedlock: {
            rules: [
              { required: true, message: '请输入婚姻状况!'},
            ]
          },
          nationId: {
            rules: [
              { required: true, message: '请输入民族!'},
            ]
          },
          nativePlace: {
            rules: [
              { required: true, message: '请输入籍贯!'},
            ]
          },
          email: {
            rules: [
              { required: true, message: '请输入邮箱!'},
              { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!'},
            ]
          },
          phone: {
            rules: [
              { required: true, message: '请输入电话号码!'},
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
            ]
          },
          departmentId: {
            rules: [
              { required: true, message: '请输入所属部门!'},
            ]
          },
          jobLevelId: {
            rules: [
              { required: true, message: '请输入职称ID!'},
            ]
          },
          engageForm: {
            rules: [
              { required: true, message: '请输入聘用形式!'},
            ]
          },
          tiptopDegree: {
            rules: [
              { required: true, message: '请输入最高学历!'},
            ]
          },
          specialty: {
            rules: [
              { required: true, message: '请输入所属专业!'},
            ]
          },
          school: {
            rules: [
              { required: true, message: '请输入毕业院校!'},
            ]
          },
          workAge: {
            rules: [
              { required: true, message: '请输入工龄!'},
            ]
          },
          beginDate: {
            rules: [
              { required: true, message: '请输入入职日期!'},
            ]
          },
          workState: {
            rules: [
              { required: true, message: '请输入在职状态!'},
            ]
          },
          /* workId: {
            rules: [
              { required: true, message: '请输入工号!'},
            ]
          }, */
          contTerm: {
            rules: [
              { required: true, message: '请输入合同期限!'},
            ]
          },
          conversionTime: {
            rules: [
              { required: true, message: '请输入转正日期!'},
            ]
          },
          beginContract: {
            rules: [
              { required: true, message: '请输入合同起始日期!'},
            ]
          },
          endContract: {
            rules: [
              { required: true, message: '请输入合同终止日期!'},
            ]
          },
          household: {
            rules: [
              { required: true, message: '请输入户籍类型!'},
            ]
          },
          householdLocation: {
            rules: [
              { required: true, message: '请输入户籍所在地!'},
            ]
          },
          estimateBeginDate: {
            rules: [
              { required: true, message: '请输入预计入职日期!'},
            ]
          },
          bankCard: {
            rules: [
              { required: true, message: '请输入银行卡号!'},
            ]
          },
          bankOfDeposit: {
            rules: [
              { required: true, message: '请输入开户行!'},
            ]
          },
          contactNumber: {
            rules: [
              { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!'},
            ]
          },
        },
        url: {
          add: "/online/api/createHrEmployee",
          edit: "/online/api/updateHrEmployee",
          get: "/online/api/getHrEmployee",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        if(record.id){
	      httpAction(this.url.get,{id:record.partyId},"post").then((res)=>{
	         if(res.success){
		        this.model = Object.assign({}, res.result);
		        this.visible = true;
		        this.$nextTick(() => {
		           this.form.setFieldsValue(pick(this.model,'wxUserId','typeId','name','nameEn','gender','birthday','idCard','wedlock','nationId','nativePlace','politicId','email','phone','address','departmentId','jobLevelId','engageForm','tiptopDegree','specialty','school','eduPath','workAge','beginDate','workState','workId','companyName','contTerm','conversionTime','notWorkDate','beginContract','endContract','uploadPath','household','householdLocation','workAddress','reportTo','estimateBeginDate','bankCard','bankOfDeposit','emergencyContact','contactRelationship','contactNumber'))
		        })   
	         }
	      })
        }
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success('提交成功!');
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'wxUserId','typeId','name','nameEn','gender','birthday','idCard','wedlock','nationId','nativePlace','politicId','email','phone','address','departmentId','jobLevelId','engageForm','tiptopDegree','specialty','school','eduPath','workAge','beginDate','workState','workId','companyName','contTerm','conversionTime','notWorkDate','beginContract','endContract','uploadPath','household','householdLocation','workAddress','reportTo','estimateBeginDate','bankCard','bankOfDeposit','emergencyContact','contactRelationship','contactNumber'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>
